package com.health.sportplay.controller;

import com.alibaba.fastjson.JSON;
import com.health.sportplay.bean.MainMenu;
import com.health.sportplay.dao.MenuDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;

@RestController
public class MenuController {
  @Autowired
  private MenuDao menuDao;

  @RequestMapping("/menus")
  public String getAllMenus(){
//    System.out.println("访问成功");
    List<MainMenu> menus = menuDao.getMenus();
    HashMap<String, Object> data = new HashMap<>();
//    int status = 404; //错误 404 正确200
    if (menus != null){
      data.put("menus",menus);
      data.put("flag",200);
    }else {
      data.put("flag",404);
    }
//        System.out.println(data);
    String s = JSON.toJSONString(data);
    return s;
  }
}
